/*
 * @Author: Kiro AI Assistant
 * @Date: 2025-01-10
 * @Description: 音乐播放页面示例
 */

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../viewmodels/music_player_view_model.dart';
import '../models/music_item_model.dart';
import '../pages/music_player_page.dart';

/// 音乐播放页面示例
class MusicPlayerPageExample extends StatelessWidget {
  const MusicPlayerPageExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('音乐播放页面示例'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              '音乐播放页面示例',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 20),
            const Text(
              '点击下方按钮测试音乐播放页面',
              style: TextStyle(fontSize: 16),
            ),
            const SizedBox(height: 40),
            ElevatedButton(
              onPressed: () => _showMusicPlayerPage(context),
              child: const Text('打开音乐播放页面'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => _showMusicPlayerPageWithSample(context),
              child: const Text('播放示例音乐'),
            ),
          ],
        ),
      ),
    );
  }

  /// 显示空的音乐播放页面
  void _showMusicPlayerPage(BuildContext context) {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => const MusicPlayerPage(),
      ),
    );
  }

  /// 显示带示例音乐的播放页面
  void _showMusicPlayerPageWithSample(BuildContext context) {
    final viewModel = context.read<MusicPlayerViewModel>();

    // 创建示例音乐
    const sampleMusic = MusicItemModel(
      id: 'sample_001',
      title: '示例歌曲',
      artist: '示例艺术家',
      album: '示例专辑',
      albumArt: 'https://picsum.photos/300/300?random=1',
      audioUrl: 'https://www.soundjay.com/misc/sounds/bell-ringing-05.wav',
      duration: Duration(minutes: 3, seconds: 30),
      sourceType: 'sample',
    );

    // 设置播放列表
    viewModel.setPlaylist([sampleMusic]);

    // 播放音乐
    viewModel.play(sampleMusic);

    // 导航到播放页面
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => const MusicPlayerPage(),
      ),
    );
  }
}
